package com.tl.juc.threadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/***
 * @Author 徐庶
 * @Slogan 致敬大师，致敬未来的你
 */
public class CustomeThreadPool {
    public static void main2(String[] args) {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                5,
                10,
                0L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        try {
            threadPool.execute(() -> {
               /* while (true){
                    Thread.interrupted()
                }*/
                System.out.println("执行..");
            });
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 把阻塞队列
            threadPool.shutdown();
            // 忽略阻塞队列
            threadPool.shutdownNow();
        }

    }


    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                5,
                10,
                5L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(10),

                 r -> {
                    Thread thread = new Thread(r);
                     thread.setUncaughtExceptionHandler((t, e) -> {
                        System.out.println("出错了：" + e.getMessage());
                    });
                    return thread;

                },
                new ThreadPoolExecutor.AbortPolicy()
        );

        // for   10W   1w
        threadPool.execute(() -> {
                System.out.println("开始");
                throw new RuntimeException("异常！");
        });

        // 1w 执行...
        //  todo.... 大量业务逻辑.....

    }
}





